package com.jingdianjichi.subject.domain.handler.subject;

import com.jingdianjichi.subject.common.enums.SubjectInfoEnum;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * SubjectTypeHandlerFactory 类
 *
 * @author 熊苏鹏1
 * @date 2025/2/20 21:08
 * @description 题目类型工厂
 */
@Component
public class SubjectTypeHandlerFactory implements InitializingBean {
    @Resource
    private List<SubjectTypeHandler> subjectTypeHandlers;
    Map<SubjectInfoEnum, SubjectTypeHandler> subjectTypeHandlerMap = new HashMap<>();
    public SubjectTypeHandler getSubjectTypeHandler(int subjectType) {
        return subjectTypeHandlerMap.get(SubjectInfoEnum.getEnumByCode(subjectType));
    }
    @Override
    public void afterPropertiesSet() throws Exception {
        subjectTypeHandlers.forEach(
                subjectTypeHandler -> subjectTypeHandlerMap.put(subjectTypeHandler.getSubjectType(), subjectTypeHandler));


    }
}








